﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="三分厂产品成本表.aspx.cs" Inherits="syc.ChengBen.三分厂.三分厂产品成本表" %>
<%@ Import  Namespace="System.Data"%>
<%@ Import  Namespace="System.Data.SqlClient"%>
<%@ Import  Namespace="System.Configuration"%>
<%@ Import  Namespace="NPOI.HSSF.UserModel"%>
<%@ Import  Namespace="NPOI.HPSF"%>
<%@ Import  Namespace="System.IO"%>

<html>
<head runat="server">
    <title></title>
</head>
<body>
<script runat="server">
        protected HSSFWorkbook hssfworkbook;
        protected double 合计;
      
        protected double 套管单位费用合计;
   
        protected double 油管单位费用合计;
      
        protected double 套管累计单位费用合计;
     
        protected double 油管累计单位费用合计;
       
        protected int part1Count;
        protected int part2Count;
        protected int part3Count;
        protected int part4Count;

        protected double 套管接箍产量;        
        protected double 油管接箍产量;        
      
        protected double 套管接箍回收金额;
        protected double 油管接箍回收金额;
        protected double 套管接箍费用;
        protected double 油管接箍费用;
        protected double 套管接箍成本;
        protected double 油管接箍成本;
    
        protected double 套管接箍累计产量;
        protected double 油管接箍累计产量;
    
        protected double 套管接箍累计回收金额;
        protected double 油管接箍累计回收金额;
        protected double 套管接箍累计费用;
        protected double 油管接箍累计费用;
        protected double 套管接箍累计成本;
        protected double 油管接箍累计成本;
        //原料投入来源材料收发存表
        //上期结存
        protected double 套管接箍光管上期结存数量;
        protected double 套管接箍光管上期结存金额;

        protected double 油管接箍光管上期结存数量;
        protected double 油管接箍光管上期结存金额;
        //本期收入      
        protected double 套管接箍光管本期收入数量;
        protected double 套管接箍光管本期收入金额;
        protected double 套管接箍光管本期累计收入数量;
        protected double 套管接箍光管本期累计收入金额;

        protected double 油管接箍光管本期收入数量;
        protected double 油管接箍光管本期收入金额;
        protected double 油管接箍光管本期累计收入数量;
        protected double 油管接箍光管本期累计收入金额;

        //本期发出
        protected double 套管接箍投入数量;
        protected double 套管接箍投入金额;
        protected double 油管接箍投入数量;
        protected double 油管接箍投入金额;
    
        protected double 套管接箍累计投入数量;
        protected double 套管接箍累计投入金额;
        protected double 油管接箍累计投入数量;      
        protected double 油管接箍累计投入金额;
    
        //protected double 套管接箍光管本期发出数量;
        //protected double 套管接箍光管本期发出金额;
        //protected double 套管接箍光管本期累计发出数量;
        //protected double 套管接箍光管本期累计发出金额;

        //protected double 油管接箍光管本期发出数量;
        //protected double 油管接箍光管本期发出金额;
        //protected double 油管接箍光管本期累计发出数量;
        //protected double 油管接箍光管本期累计发出金额;

        //本期结存支数
        protected double 套管接箍磷化支数;
        protected double 套管接箍半成品支数;
        protected double 套管接箍光管本期结存支数;

        protected double 油管接箍磷化支数;
        protected double 油管接箍半成品支数;
        protected double 油管接箍光管本期结存支数;

        protected double 套管接箍光管本期结存数量;
        protected double 油管接箍光管本期结存数量;

        protected double 套管接箍光管本期结存金额;
        protected double 油管接箍光管本期结存金额;
        
        
          protected void Page_Load(object sender, EventArgs e)
           {
            if (!IsPostBack)
            {
                 Button_Query_Click(null, null);
                this.Year.SelectedValue = DateTime.Today.Year.ToString();
                this.Month.SelectedValue = DateTime.Today.Month.ToString();
            }
           }
           protected void Button_Query_Click(object sender, EventArgs e)
           {
                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                Conn.Open();
                SqlCommand Cmd = new SqlCommand();
                Cmd.Connection = Conn;
                string sql="";
               DataSet ds = new DataSet();
               string sqlpartCount = @"
               select 财务处.value('count(/root/rnode[1]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份
               select 财务处.value('count(/root/rnode[2]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份
               select 财务处.value('count(/root/rnode[3]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份
               select 财务处.value('count(/root/rnode[4]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份";
               sqlpartCount = sqlpartCount.Replace("@年度", this.Year.Text);
               sqlpartCount = sqlpartCount.Replace("@月份", this.Month.Text);
               SqlDataAdapter sda = new SqlDataAdapter(sqlpartCount, Conn);
               sda.Fill(ds);
               DataTable dt1 = ds.Tables[0];
               DataTable dt2 = ds.Tables[1];
               DataTable dt3 = ds.Tables[2];
               DataTable dt4 = ds.Tables[3];
               try
               {
                   part1Count = int.Parse(dt1.Rows[0][0].ToString());

                   part2Count = int.Parse(dt2.Rows[0][0].ToString());

                   part3Count = int.Parse(dt3.Rows[0][0].ToString());

                   part4Count = int.Parse(dt4.Rows[0][0].ToString());
               }
               catch
               {
                   part1Count = 0;

                   part2Count = 0;

                   part3Count = 0;

                   part4Count = 0;
               }
                //part1
                string str1 = @"
        select '一、'+财务处.value('(/root/rnode/@name)[1]','nvarchar(10)')
        ,财务处.value('(/root/rnode/@cash)[1]','float')
        ,round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,财务处.value('(/root/rnode/@cash)[1]','float') as 合计
        ,round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,TJ55
        ,(select isnull(sum(TJ55),0) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,YJ55
        ,(select isnull(sum(YJ55),0) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        from test where year=@年度 and  分厂=3 and month=@月份 ";
                string sql1 = "";
                for (int i = 0; i < part1Count; i++)
                {
                    sql1 += @"union all
                  select 财务处.value('(/root/rnode[1]/node/@name)[@i]','nvarchar(10)')
        ,财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')
        ,round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),@月份)/TJ55,@月份)
        ,(select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
        ,round((select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
        ,round((select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,0 as 合计
        ,0 
        ,0
        ,0
        ,0
        ,0 
        ,0
        ,0
        ,0
        ,0
        ,0
        ,0
        ,0
        from test where year=@年度 and  分厂=3 and month=@月份 
                     ";
                    sql1 = sql1.Replace("@i", (i + 1).ToString());
                }
                //part2
                string str2 = @"union all select '二、'+财务处.value('(/root/rnode/@name)[2]','nvarchar(10)')
        ,财务处.value('(/root/rnode/@cash)[2]','float')
        ,round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,财务处.value('(/root/rnode/@cash)[2]','float') as 合计
        ,round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,0
        ,0
        ,0
        ,0
        from test where year=@年度 and  分厂=3 and month=@月份 ";
                string sql2 = "";
                for (int i = 0; i < part2Count; i++)
                {
                    sql2 += @"union all
                  select 财务处.value('(/root/rnode[2]/node/@name)[@i]','nvarchar(10)')
        ,财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')
        ,round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
        ,round((select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
        ,round((select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,0 as 合计
        ,0 
        ,0
        ,0
        ,0
        ,0 
        ,0
        ,0
        ,0
        ,0
        ,0
        ,0
        ,0
        from test where year=@年度 and  分厂=3 and month=@月份 
                     ";
                    sql2 = sql2.Replace("@i", (i + 1).ToString());
                }
                string str3 = @"union all select '三、'+财务处.value('(/root/rnode/@name)[3]','nvarchar(10)')
        ,财务处.value('(/root/rnode/@cash)[3]','float')
        ,round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,财务处.value('(/root/rnode/@cash)[3]','float') as 合计
        ,round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,0
        ,0
        ,0
        ,0
        from test where year=@年度 and  分厂=3 and month=@月份 ";
                string sql3 = "";
                for (int i = 0; i < part3Count; i++)
                {
                    sql3 += @"union all
                  select 财务处.value('(/root/rnode[3]/node/@name)[@i]','nvarchar(10)')
        ,财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')
        ,round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
        ,round((select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
        ,round((select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,0 as 合计
        ,0 
        ,0
        ,0
        ,0
        ,0 
        ,0
        ,0
        ,0
        ,0
        ,0
        ,0
        ,0
        from test where year=@年度 and  分厂=3 and month=@月份 
                     ";
                    sql3 = sql3.Replace("@i", (i + 1).ToString());
                }
                string str4 = @"union all select '四、'+财务处.value('(/root/rnode/@name)[4]','nvarchar(10)')
        ,财务处.value('(/root/rnode/@cash)[4]','float')
        ,round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,财务处.value('(/root/rnode/@cash)[4]','float') as 合计
        ,round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
        ,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,0
        ,0
        ,0
        ,0
        from test where year=@年度 and  分厂=3 and month=@月份 ";
                string sql4 = "";
                for (int i = 0; i < part4Count; i++)
                {
                    sql4 += @"union all
                  select 财务处.value('(/root/rnode[4]/node/@name)[@i]','nvarchar(10)')
        ,财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')
        ,round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
        ,round((select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
        ,round(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
        ,(select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
        ,round((select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
        ,0 as 合计
        ,0 
        ,0
        ,0
        ,0
        ,0 
        ,0
        ,0
        ,0
        ,0
        ,0
        ,0
        ,0
        from test where year=@年度 and  分厂=3 and month=@月份 
             ";
            sql4 = sql4.Replace("@i", (i + 1).ToString());
        }
        sql = str1 + sql1 + str2 + sql2 + str3 + sql3 + str4 + sql4;
        sql = sql.Replace("@年度", this.Year.Text);
        sql = sql.Replace("@月份", this.Month.Text);
         Cmd.CommandText = sql;
           
            SqlDataReader Reader = Cmd.ExecuteReader();
            try
            {               
                while (Reader.Read())
                    {
                        合计 += double.Parse(Reader[10].ToString());
                        套管接箍费用 += double.Parse(Reader[11].ToString());
                        套管单位费用合计 += double.Parse(Reader[12].ToString());
                        套管接箍累计费用 += double.Parse(Reader[13].ToString());
                        套管累计单位费用合计 += double.Parse(Reader[14].ToString());
                        油管接箍费用 += double.Parse(Reader[15].ToString());
                        油管单位费用合计 += double.Parse(Reader[16].ToString());
                        油管接箍累计费用 += double.Parse(Reader[17].ToString());
                        油管累计单位费用合计 += double.Parse(Reader[18].ToString());

                        套管接箍产量 += double.Parse(Reader[19].ToString());
                        套管接箍累计产量 += double.Parse(Reader[20].ToString());
                        油管接箍产量 += double.Parse(Reader[21].ToString());
                        油管接箍累计产量 += double.Parse(Reader[22].ToString());
                     }
                Reader.Close();
                string sql5 =@"
                declare @套管接箍光管上期结存数量 float
                declare @套管接箍光管上期结存金额 float
                declare @油管接箍光管上期结存数量 float
                declare @油管接箍光管上期结存金额 float                
                
                declare @套管接箍光管本期收入数量 float
                declare @套管接箍光管本期收入金额 float                
                declare @油管接箍光管本期收入数量 float
                declare @油管接箍光管本期收入金额 float 
                declare @套管接箍光管本期累计收入数量 float
                declare @套管接箍光管本期累计收入金额 float                
                declare @油管接箍光管本期累计收入数量 float
                declare @油管接箍光管本期累计收入金额 float               
                          
                declare @套管磷化支数 float
                declare @套管半成品支数  float                
                declare @油管磷化支数  float
                declare @油管半成品支数  float   
                
                declare @套管接箍光管本期结存金额 float
                declare @油管接箍光管本期结存金额 float                
                
             
                
                select @油管接箍光管上期结存数量=结存支数*0.0032,@油管接箍光管上期结存金额=(本期收入金额/本期收入数量)*@油管接箍光管上期结存数量 from  三分厂原料收发存表 where 年度=@上年度 and 月份=@上月份 and 原料类别ID=1                    
                select @套管接箍光管上期结存数量=结存支数*0.01,@套管接箍光管上期结存金额=(本期收入金额/本期收入数量)*@套管接箍光管上期结存数量 from  三分厂原料收发存表 where 年度=@上年度 and 月份=@上月份 and 原料类别ID=2         
                
                select @油管接箍光管本期收入数量=本期收入数量,@油管接箍光管本期收入金额=本期收入金额 from  三分厂原料收发存表 where 年度=@年度 and 月份=@月份 and 原料类别ID=1                                        
                select @套管接箍光管本期收入数量=本期收入数量,@套管接箍光管本期收入金额=本期收入金额 from  三分厂原料收发存表 where 年度=@年度 and 月份=@月份 and 原料类别ID=2
                select @油管接箍光管本期累计收入数量=isnull(sum(本期收入数量),0),@油管接箍光管本期累计收入金额=isnull(sum(本期收入金额),0) from  三分厂原料收发存表 where 年度=@年度 and 月份 between 1 and @月份 and 原料类别ID=1                 
                select @套管接箍光管本期累计收入数量=isnull(sum(本期收入数量),0),@套管接箍光管本期累计收入金额=isnull(sum(本期收入金额),0) from 三分厂原料收发存表 where 年度=@年度 and 月份 between 1 and @月份 and 原料类别ID=2                      
                                
                select   @油管磷化支数 =本期已磷化支数,@油管半成品支数 =本期半成品支数 from  三分厂原料收发存表  where 年度=@年度 and 月份=@月份 and 原料类别ID=1    
                select   @套管磷化支数 =本期已磷化支数,@套管半成品支数 =本期半成品支数 from  三分厂原料收发存表  where 年度=@年度 and 月份=@月份 and 原料类别ID=2 
                       
                select  isnull(@套管接箍光管上期结存数量,0),isnull(@套管接箍光管上期结存金额,0)   
                        ,isnull(@油管接箍光管上期结存数量,0),isnull(@油管接箍光管上期结存金额,0)
                        ,isnull(@套管接箍光管本期收入数量,0),isnull(@套管接箍光管本期收入金额,0),isnull(@套管接箍光管本期累计收入数量,0),isnull(@套管接箍光管本期累计收入金额,0)
                        ,isnull(@油管接箍光管本期收入数量,0),isnull(@油管接箍光管本期收入金额,0),isnull(@油管接箍光管本期累计收入数量,0),isnull(@油管接箍光管本期累计收入金额,0)
                        ,isnull(@套管磷化支数,0),isnull(@套管半成品支数,0)
                        ,isnull(@油管磷化支数,0),isnull(@油管半成品支数,0)                                                                                                                                                                                                                                    
        ";

        sql5 = sql5.Replace("@年度", this.Year.Text);
        sql5 = sql5.Replace("@月份", this.Month.Text);
        if ((int.Parse(this.Month.Text) - 1) == 0)
        {
            sql5 = sql5.Replace("@上年度", (int.Parse(this.Year.Text) - 1).ToString());
            sql5 = sql5.Replace("@上月份", "12");
        }
        else
        {
            sql5 = sql5.Replace("@上年度", (int.Parse(this.Year.Text)).ToString());
            sql5 = sql5.Replace("@上月份", (int.Parse(this.Month.Text) - 1).ToString());
        }

        Cmd.CommandText = sql5;
        Reader = Cmd.ExecuteReader();

        if (Reader.Read())
        {
            //上期结存
            套管接箍光管上期结存数量 = double.Parse(Reader[0].ToString());
            套管接箍光管上期结存金额 = double.Parse(Reader[1].ToString());
            油管接箍光管上期结存数量 = double.Parse(Reader[2].ToString());
            油管接箍光管上期结存金额 = double.Parse(Reader[3].ToString());
            //本期收入
            套管接箍光管本期收入数量 = double.Parse(Reader[4].ToString());
            套管接箍光管本期收入金额 = double.Parse(Reader[5].ToString()); ;
            套管接箍光管本期累计收入数量 = double.Parse(Reader[6].ToString());
            套管接箍光管本期累计收入金额 = double.Parse(Reader[7].ToString());

            油管接箍光管本期收入数量 = double.Parse(Reader[8].ToString());
            油管接箍光管本期收入金额 = double.Parse(Reader[9].ToString()); ;
            油管接箍光管本期累计收入数量 = double.Parse(Reader[10].ToString());
            油管接箍光管本期累计收入金额 = double.Parse(Reader[11].ToString());
            //本期结存
            套管接箍磷化支数 = double.Parse(Reader[12].ToString());
            套管接箍半成品支数 = double.Parse(Reader[13].ToString());
            油管接箍磷化支数 = double.Parse(Reader[14].ToString());
            油管接箍半成品支数 = double.Parse(Reader[15].ToString());

            套管接箍光管本期结存支数 = (套管接箍磷化支数 + 套管接箍半成品支数);
            油管接箍光管本期结存支数 = (油管接箍磷化支数 + 油管接箍半成品支数);

            套管接箍光管本期结存数量 = double.Parse((套管接箍光管本期结存支数 * 10 / 1000).ToString("0.000"));
            油管接箍光管本期结存数量 = double.Parse((油管接箍光管本期结存支数 * 3.2 / 1000).ToString("0.000"));
            double f1 = 套管接箍光管本期收入金额 / 套管接箍光管本期收入数量;
            double f2 = 油管接箍光管本期收入金额 / 油管接箍光管本期收入数量;
            套管接箍光管本期结存金额 = f1 * 套管接箍光管本期结存数量;
            油管接箍光管本期结存金额 = f2 * 油管接箍光管本期结存数量;

            套管接箍投入数量 = double.Parse(套管接箍光管上期结存数量.ToString("0.000")) + double.Parse(套管接箍光管本期收入数量.ToString("0.000")) - double.Parse(套管接箍光管本期结存数量.ToString("0.000"));
            套管接箍投入金额= double.Parse(套管接箍光管上期结存金额.ToString("0.00")) + double.Parse(套管接箍光管本期收入金额.ToString("0.00")) - double.Parse(套管接箍光管本期结存金额.ToString("0.00"));


            油管接箍投入数量 = double.Parse(油管接箍光管上期结存数量.ToString("0.000")) + double.Parse(油管接箍光管本期收入数量.ToString("0.000")) - double.Parse(油管接箍光管本期结存数量.ToString("0.000"));
            油管接箍投入金额 = double.Parse(油管接箍光管上期结存金额.ToString("0.00")) + double.Parse(油管接箍光管本期收入金额.ToString("0.00")) - double.Parse(油管接箍光管本期结存金额.ToString("0.00"));

        }
        Reader.Close();

        for (int i = 1; i <= int.Parse(this.Month.Text); i++)
        {
            string sql6 = @"
                declare @套管接箍光管上期结存数量 float
                declare @套管接箍光管上期结存金额 float
                declare @油管接箍光管上期结存数量 float
                declare @油管接箍光管上期结存金额 float                
                
                declare @套管接箍光管本期收入数量 float
                declare @套管接箍光管本期收入金额 float                
                declare @油管接箍光管本期收入数量 float
                declare @油管接箍光管本期收入金额 float 
                declare @套管接箍光管本期累计收入数量 float
                declare @套管接箍光管本期累计收入金额 float                
                declare @油管接箍光管本期累计收入数量 float
                declare @油管接箍光管本期累计收入金额 float               
                          
                declare @套管磷化支数 float
                declare @套管半成品支数  float                
                declare @油管磷化支数  float
                declare @油管半成品支数  float   
                
                declare @套管接箍光管本期结存金额 float
                declare @油管接箍光管本期结存金额 float                
                
             
                
                select @油管接箍光管上期结存数量=结存支数*0.0032,@油管接箍光管上期结存金额=(本期收入金额/本期收入数量)*@油管接箍光管上期结存数量 from  三分厂原料收发存表 where 年度=@上年度 and 月份=@上月份 and 原料类别ID=1                    
                select @套管接箍光管上期结存数量=结存支数*0.01,@套管接箍光管上期结存金额=(本期收入金额/本期收入数量)*@套管接箍光管上期结存数量 from  三分厂原料收发存表 where 年度=@上年度 and 月份=@上月份 and 原料类别ID=2         
                
                select @油管接箍光管本期收入数量=本期收入数量,@油管接箍光管本期收入金额=本期收入金额 from  三分厂原料收发存表 where 年度=@年度 and 月份=@月份 and 原料类别ID=1                                        
                select @套管接箍光管本期收入数量=本期收入数量,@套管接箍光管本期收入金额=本期收入金额 from  三分厂原料收发存表 where 年度=@年度 and 月份=@月份 and 原料类别ID=2
                select @油管接箍光管本期累计收入数量=isnull(sum(本期收入数量),0),@油管接箍光管本期累计收入金额=isnull(sum(本期收入金额),0) from  三分厂原料收发存表 where 年度=@年度 and 月份 between 1 and @月份 and 原料类别ID=1                 
                select @套管接箍光管本期累计收入数量=isnull(sum(本期收入数量),0),@套管接箍光管本期累计收入金额=isnull(sum(本期收入金额),0) from 三分厂原料收发存表 where 年度=@年度 and 月份 between 1 and @月份 and 原料类别ID=2                      
                                
                select   @油管磷化支数 =本期已磷化支数,@油管半成品支数 =本期半成品支数 from  三分厂原料收发存表  where 年度=@年度 and 月份=@月份 and 原料类别ID=1    
                select   @套管磷化支数 =本期已磷化支数,@套管半成品支数 =本期半成品支数 from  三分厂原料收发存表  where 年度=@年度 and 月份=@月份 and 原料类别ID=2 
                       
                select  isnull(@套管接箍光管上期结存数量,0),isnull(@套管接箍光管上期结存金额,0)   
                        ,isnull(@油管接箍光管上期结存数量,0),isnull(@油管接箍光管上期结存金额,0)
                        ,isnull(@套管接箍光管本期收入数量,0),isnull(@套管接箍光管本期收入金额,0),isnull(@套管接箍光管本期累计收入数量,0),isnull(@套管接箍光管本期累计收入金额,0)
                        ,isnull(@油管接箍光管本期收入数量,0),isnull(@油管接箍光管本期收入金额,0),isnull(@油管接箍光管本期累计收入数量,0),isnull(@油管接箍光管本期累计收入金额,0)
                        ,isnull(@套管磷化支数,0),isnull(@套管半成品支数,0)
                        ,isnull(@油管磷化支数,0),isnull(@油管半成品支数,0) 
                                                                                                                                                                                                                                   
        ";
            sql6 = sql6.Replace("@年度", this.Year.Text);
            sql6 = sql6.Replace("@月份", i.ToString());
            if ((i - 1) == 0)
            {
                sql6 = sql6.Replace("@上年度", (int.Parse(this.Year.Text) - 1).ToString());
                sql6 = sql6.Replace("@上月份", "12");
            }
            else
            {
                sql6 = sql6.Replace("@上年度", (int.Parse(this.Year.Text)).ToString());
                sql6 = sql6.Replace("@上月份", (i - 1).ToString());
            }
            Cmd.CommandText = sql6;
            Reader = Cmd.ExecuteReader();

            if (Reader.Read())
            {
                //上期结存
                套管接箍光管上期结存数量 = double.Parse(Reader[0].ToString());
                套管接箍光管上期结存金额 = double.Parse(Reader[1].ToString());
                油管接箍光管上期结存数量 = double.Parse(Reader[2].ToString());
                油管接箍光管上期结存金额 = double.Parse(Reader[3].ToString());
                //本期收入
                套管接箍光管本期收入数量 = double.Parse(Reader[4].ToString());
                套管接箍光管本期收入金额 = double.Parse(Reader[5].ToString()); ;
                套管接箍光管本期累计收入数量 = double.Parse(Reader[6].ToString());
                套管接箍光管本期累计收入金额 = double.Parse(Reader[7].ToString());

                油管接箍光管本期收入数量 = double.Parse(Reader[8].ToString());
                油管接箍光管本期收入金额 = double.Parse(Reader[9].ToString()); ;
                油管接箍光管本期累计收入数量 = double.Parse(Reader[10].ToString());
                油管接箍光管本期累计收入金额 = double.Parse(Reader[11].ToString());
                //本期结存
                套管接箍磷化支数 = double.Parse(Reader[12].ToString());
                套管接箍半成品支数 = double.Parse(Reader[13].ToString());
                油管接箍磷化支数 = double.Parse(Reader[14].ToString());
                油管接箍半成品支数 = double.Parse(Reader[15].ToString());

                套管接箍光管本期结存支数 = (套管接箍磷化支数 + 套管接箍半成品支数);
                油管接箍光管本期结存支数 = (油管接箍磷化支数 + 油管接箍半成品支数);

                套管接箍光管本期结存数量 = double.Parse((套管接箍光管本期结存支数 * 10 / 1000).ToString("0.000"));
                油管接箍光管本期结存数量 = double.Parse((油管接箍光管本期结存支数 * 3.2 / 1000).ToString("0.000"));
                double f1 = 套管接箍光管本期收入金额 / 套管接箍光管本期收入数量;
                double f2 = 油管接箍光管本期收入金额 / 油管接箍光管本期收入数量;
                套管接箍光管本期结存金额 = f1 * 套管接箍光管本期结存数量;
                油管接箍光管本期结存金额 = f2 * 油管接箍光管本期结存数量;

                套管接箍投入数量 = double.Parse((double.Parse(套管接箍光管上期结存数量.ToString("0.000")) + double.Parse(套管接箍光管本期收入数量.ToString("0.000")) - double.Parse(套管接箍光管本期结存数量.ToString("0.000"))).ToString("0.000"));
                套管接箍投入金额 = double.Parse((double.Parse(套管接箍光管上期结存金额.ToString("0.00")) + double.Parse(套管接箍光管本期收入金额.ToString("0.00")) - double.Parse(套管接箍光管本期结存金额.ToString("0.00"))).ToString("0.00"));


                油管接箍投入数量 = double.Parse((double.Parse(油管接箍光管上期结存数量.ToString("0.000")) + double.Parse(油管接箍光管本期收入数量.ToString("0.000")) - double.Parse(油管接箍光管本期结存数量.ToString("0.000"))).ToString("0.000"));
                油管接箍投入金额 = double.Parse((double.Parse(油管接箍光管上期结存金额.ToString("0.00")) + double.Parse(油管接箍光管本期收入金额.ToString("0.00")) - double.Parse(油管接箍光管本期结存金额.ToString("0.00"))).ToString("0.00"));
               
            }
            Reader.Close();
            套管接箍累计投入数量 += 套管接箍投入数量;
            套管接箍累计投入金额 += 套管接箍投入金额;
            油管接箍累计投入数量 += 油管接箍投入数量;
            油管接箍累计投入金额 += 油管接箍投入金额;           
        }
            string sql7 = @"    declare @套管接箍回收金额 float
                                declare @油管接箍回收金额 float      
                                declare @套管接箍累计回收金额 float
                                declare @油管接箍累计回收金额 float                  
                                select @套管接箍回收金额=-isnull(sum(回收金额),0) from 分厂废料回收金额 where 年度=@年度 and 月份=@月份 and 分厂ID=3 and 产品类别ID=4
                                select @油管接箍回收金额=-isnull(sum(回收金额),0) from 分厂废料回收金额 where 年度=@年度 and 月份=@月份 and 分厂ID=3 and 产品类别ID=3
                                select @套管接箍累计回收金额=-isnull(sum(回收金额),0) from 分厂废料回收金额 where 年度=@年度 and 月份 between 1 and @月份 and 分厂ID=3 and 产品类别ID=4
                                select @油管接箍累计回收金额=-isnull(sum(回收金额),0) from 分厂废料回收金额 where 年度=@年度 and 月份 between 1 and @月份 and 分厂ID=3 and 产品类别ID=3     
                                select @套管接箍回收金额,@套管接箍累计回收金额,@油管接箍回收金额,@油管接箍累计回收金额                                                   
                              ";
            sql7 = sql7.Replace("@年度", this.Year.Text);
            sql7 = sql7.Replace("@月份", this.Month.Text);
            Cmd.CommandText = sql7;
            Reader = Cmd.ExecuteReader();

            if (Reader.Read())
            {
                套管接箍回收金额 = double.Parse(Reader[0].ToString());
                套管接箍累计回收金额 = double.Parse(Reader[1].ToString());
                油管接箍回收金额 = double.Parse(Reader[2].ToString());
                油管接箍累计回收金额 = double.Parse(Reader[3].ToString());
            }
            套管接箍成本 = 套管接箍投入金额 + 套管接箍回收金额 + 套管接箍费用;
            油管接箍成本 = 油管接箍投入金额 + 油管接箍回收金额 + 油管接箍费用;
            套管接箍累计成本 = 套管接箍累计投入金额 + 套管接箍累计回收金额 + 套管接箍累计费用;
            油管接箍累计成本 = 油管接箍累计投入金额 + 油管接箍累计回收金额 + 油管接箍累计费用;    
                Cmd.Clone();
                Conn.Close();
            }
            catch (Exception ex)
            {
                this.Message.Text = "请输入套管或油管产量!";
                return;
            }
           }
           protected void WriteToFile()
           {
            DateTime d;       
            d = DateTime.Today;       
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment; filename=\"" + d.ToShortDateString() + ".xls\"");
            hssfworkbook.Write(Response.OutputStream);
           }

           protected void InitializeWorkbook()
           {

            FileStream file = new FileStream(HttpContext.Current.Server.MapPath("/ChengBen/三分厂/模板/产品成本.xls"), FileMode.Open, FileAccess.Read);

            hssfworkbook = new HSSFWorkbook(file);

            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
            dsi.Company = "陕西延长石油材料有限公司";
            hssfworkbook.DocumentSummaryInformation = dsi;

            SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
            si.Subject = "报表";
            si.Title = "三分厂产品成本表";
            hssfworkbook.SummaryInformation = si;
           }
           protected void Button1_Click(object sender, EventArgs e)
           {
               InitializeWorkbook();
               HSSFSheet sheet1 = hssfworkbook.GetSheet("三分厂产品成本");
               sheet1.GetRow(1).GetCell(0).SetCellValue(this.Year.Text + "年" + this.Month.Text + "月");
               Button_Query_Click(null, null);
               sheet1.GetRow(5).GetCell(1).SetCellValue(套管接箍产量);
               sheet1.GetRow(5).GetCell(2).SetCellValue(套管接箍累计产量);
               sheet1.GetRow(5).GetCell(3).SetCellValue(套管接箍投入数量);
               sheet1.GetRow(5).GetCell(4).SetCellValue(套管接箍投入金额);
               sheet1.GetRow(5).GetCell(5).SetCellValue(套管接箍累计投入数量);
               sheet1.GetRow(5).GetCell(6).SetCellValue(套管接箍累计投入金额);
               sheet1.GetRow(5).GetCell(7).SetCellValue(套管接箍回收金额);
               sheet1.GetRow(5).GetCell(8).SetCellValue(套管接箍累计回收金额);
               sheet1.GetRow(5).GetCell(9).SetCellValue(套管接箍费用);
               sheet1.GetRow(5).GetCell(10).SetCellValue(套管接箍累计费用);
               sheet1.GetRow(5).GetCell(11).SetCellValue(套管接箍成本);
               sheet1.GetRow(5).GetCell(12).SetCellValue(套管接箍累计成本);

               sheet1.GetRow(6).GetCell(1).SetCellValue(油管接箍产量);
               sheet1.GetRow(6).GetCell(2).SetCellValue(油管接箍累计产量);
               sheet1.GetRow(6).GetCell(3).SetCellValue(油管接箍投入数量);
               sheet1.GetRow(6).GetCell(4).SetCellValue(油管接箍投入金额);
               sheet1.GetRow(6).GetCell(5).SetCellValue(油管接箍累计投入数量);
               sheet1.GetRow(6).GetCell(6).SetCellValue(油管接箍累计投入金额);
               sheet1.GetRow(6).GetCell(7).SetCellValue(油管接箍回收金额);
               sheet1.GetRow(6).GetCell(8).SetCellValue(油管接箍累计回收金额);
               sheet1.GetRow(6).GetCell(9).SetCellValue(油管接箍费用);
               sheet1.GetRow(6).GetCell(10).SetCellValue(油管接箍累计费用);
               sheet1.GetRow(6).GetCell(11).SetCellValue(油管接箍成本);
               sheet1.GetRow(6).GetCell(12).SetCellValue(油管接箍累计成本);
               
               
               sheet1.GetRow(7).GetCell(2).SetCellValue(套管接箍累计产量 + 油管接箍累计产量);             
               sheet1.GetRow(7).GetCell(4).SetCellValue(套管接箍投入金额 + 油管接箍投入金额);         
               sheet1.GetRow(7).GetCell(6).SetCellValue(套管接箍累计投入金额+油管接箍累计投入金额);
               sheet1.GetRow(7).GetCell(7).SetCellValue(套管接箍回收金额+油管接箍回收金额);
               sheet1.GetRow(7).GetCell(8).SetCellValue(套管接箍累计回收金额+油管接箍累计回收金额);
               sheet1.GetRow(7).GetCell(9).SetCellValue(套管接箍费用+油管接箍费用);
               sheet1.GetRow(7).GetCell(10).SetCellValue(套管接箍累计费用+油管接箍累计费用);
               sheet1.GetRow(7).GetCell(11).SetCellValue(套管接箍成本+油管接箍成本);
               sheet1.GetRow(7).GetCell(12).SetCellValue(套管接箍累计成本 + 油管接箍累计成本);
               string op = (String)Session["OperatorName"];
               sheet1.GetRow(8).GetCell(9).SetCellValue("制表：" + op);
               WriteToFile();
               Response.End();        
           }

</script>
    <script type="text/javascript" language="javascript" src="/common.js"></script>
   <form id="form1" runat="server">  
      <div id="wintop" class="wintop"><span lang="zh-cn">三分厂产品成本表</span></div>
        <asp:Panel ID="Panel1" runat="server" CssClass="panel" Height="36px" >   
              年份：<asp:DropDownList ID="Year" runat="server">         
            <asp:ListItem>2010</asp:ListItem>
            <asp:ListItem>2011</asp:ListItem>
            <asp:ListItem>2012</asp:ListItem>
            <asp:ListItem>2013</asp:ListItem>
            <asp:ListItem>2014</asp:ListItem>
            <asp:ListItem>2015</asp:ListItem>   
            <asp:ListItem>2016</asp:ListItem>
            <asp:ListItem>2017</asp:ListItem>
            <asp:ListItem>2018</asp:ListItem>
            <asp:ListItem>2019</asp:ListItem>
            <asp:ListItem>2020</asp:ListItem>                
            </asp:DropDownList>
            <span lang="zh-cn">&nbsp;月份：</span><asp:DropDownList ID="Month" runat="server">
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
                <asp:ListItem>4</asp:ListItem>
                <asp:ListItem>5</asp:ListItem>
                <asp:ListItem>6</asp:ListItem>
                <asp:ListItem>7</asp:ListItem>
                <asp:ListItem>8</asp:ListItem>
                <asp:ListItem>9</asp:ListItem>
                <asp:ListItem>10</asp:ListItem>
                <asp:ListItem>11</asp:ListItem>
                <asp:ListItem>12</asp:ListItem>
            </asp:DropDownList>
      <span lang="zh-cn">&nbsp;&nbsp;</span><asp:Button ID="Button_Query"
            runat="server" Text="查看报表" CssClass="button" UseSubmitBehavior="true" onclick="Button_Query_Click" 
             />            
            &nbsp;<asp:Button ID="Button1" runat="server" class="button" onclick="Button1_Click" 
                Text="导 出" />
      </asp:Panel>
        <asp:Panel ID="Panel2" runat="server" CssClass="panel2">
        <asp:Label ID="Message" runat="server" Text="·准备就绪" CssClass="prompt" Visible="True"></asp:Label>
        </asp:Panel> 
     <div align="center">  
    <style>
<style>
<!--table
	{mso-displayed-decimal-separator:"\.";
	mso-displayed-thousand-separator:"\,";}
@page
	{margin:1.01in .14in 1.0in .24in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-page-orientation:landscape;}
tr
	{mso-height-source:auto;
	mso-ruby-visibility:none;}
col
	{mso-width-source:auto;
	mso-ruby-visibility:none;}
br
	{mso-data-placement:same-cell;}
.style0
	{mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-background-source:auto;
	mso-pattern:auto;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	border:none;
	mso-protection:locked visible;
	mso-style-name:常规;
	mso-style-id:0;}
td
	{mso-style-parent:style0;
	padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl24
	{mso-style-parent:style0;
	font-size:16.0pt;}
.xl25
	{mso-style-parent:style0;
	text-align:center;}
.xl26
	{mso-style-parent:style0;
	font-size:10.0pt;}
.xl27
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;}
.xl28
	{mso-style-parent:style0;
	vertical-align:bottom;}
.xl29
	{mso-style-parent:style0;
	font-family:"Times New Roman", serif;
	mso-font-charset:0;}
.xl30
	{mso-style-parent:style0;
	font-size:10.0pt;
	mso-number-format:"0\.00_ ";
	text-align:center;}
.xl31
	{mso-style-parent:style0;
	font-size:11.0pt;
	vertical-align:bottom;}
.xl32
	{mso-style-parent:style0;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl33
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl34
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border:.5pt solid windowtext;}
.xl35
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border:.5pt solid windowtext;}
.xl36
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl37
	{mso-style-parent:style0;
	font-size:10.0pt;
	border:.5pt solid windowtext;}
.xl38
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl39
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:left;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl40
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
.xl41
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl42
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl43
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;
	white-space:normal;}
.xl44
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;
	white-space:normal;}
.xl45
	{mso-style-parent:style0;
	font-size:18.0pt;
	text-align:center;}
.xl46
	{mso-style-parent:style0;
	text-align:center;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;
	white-space:normal;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;
	display:none;}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>三分厂产品成本</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Print>
      <x:ValidPrinterInfo/>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:HorizontalResolution>600</x:HorizontalResolution>
      <x:VerticalResolution>600</x:VerticalResolution>
     </x:Print>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>13</x:ActiveRow>
       <x:ActiveCol>8</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>7905</x:WindowHeight>
  <x:WindowWidth>12540</x:WindowWidth>
  <x:WindowTopX>600</x:WindowTopX>
  <x:WindowTopY>285</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>

<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=1080 style='border-collapse:
 collapse;table-layout:fixed;width:812pt'>
 <col width=69 style='mso-width-source:userset;mso-width-alt:2208;width:52pt'>
 <col width=54 style='mso-width-source:userset;mso-width-alt:1728;width:41pt'>
 <col width=66 style='mso-width-source:userset;mso-width-alt:2112;width:50pt'>
 <col width=69 style='mso-width-source:userset;mso-width-alt:2208;width:52pt'>
 <col width=92 style='mso-width-source:userset;mso-width-alt:2944;width:69pt'>
 <col width=69 style='mso-width-source:userset;mso-width-alt:2208;width:52pt'>
 <col width=94 style='mso-width-source:userset;mso-width-alt:3008;width:71pt'>
 <col width=96 span=4 style='mso-width-source:userset;mso-width-alt:3072;
 width:72pt'>
 <col width=91 style='mso-width-source:userset;mso-width-alt:2912;width:68pt'>
 <col width=92 style='mso-width-source:userset;mso-width-alt:2944;width:69pt'>
 <tr height=52 style='mso-height-source:userset;height:39.0pt'>
  <td colspan=13 height=52 class=xl45 width=1080 style='height:39.0pt;
  width:812pt'>三分厂产品成本计算表</td>
 </tr>
 <tr height=20 style='mso-height-source:userset;height:15.0pt'>
  <td colspan=13 height=20 class=xl25 style='height:15.0pt'><%=this.Year.Text %>年<span
  style='mso-spacerun:yes'></span><%=this.Month.Text %>月</td>
 </tr>
 <tr height=20 style='mso-height-source:userset;height:15.0pt'>
  <td colspan=13 height=20 class=xl46 width=1080 style='height:15.0pt;
  width:812pt'><span
  style='mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  </span>单位：元</td>
 </tr>
 <tr height=46 style='mso-height-source:userset;height:34.5pt'>
  <td rowspan=2 height=92 class=xl40 style='border-bottom:.5pt solid black;
  height:69.0pt;border-top:none'>产品名称</td>
  <td colspan=2 class=xl35 style='border-left:none'>入库量(支)</td>
  <td colspan=2 class=xl41 style='border-right:.5pt solid black;border-left:
  none'>本期投入</td>
  <td colspan=2 class=xl41 style='border-right:.5pt solid black;border-left:
  none'>累计投入</td>
  <td colspan=2 class=xl43 width=192 style='border-right:.5pt solid black;
  border-left:none;width:144pt'>回收<br>
    (铁屑/切头)</td>
  <td colspan=2 class=xl41 style='border-right:.5pt solid black;border-left:
  none'>费用</td>
  <td colspan=2 class=xl35 style='border-left:none'>成本</td>
 </tr>
 <tr height=46 style='mso-height-source:userset;height:34.5pt'>
  <td height=46 class=xl36 style='height:34.5pt;border-left:none'>本期</td>
  <td class=xl36 style='border-left:none'>累计</td>
  <td class=xl35 style='border-top:none;border-left:none'>数量(吨)</td>
  <td class=xl35 style='border-top:none;border-left:none'>金额</td>
  <td class=xl35 style='border-top:none;border-left:none'>数量(吨)</td>
  <td class=xl35 style='border-top:none;border-left:none'>金额</td>
  <td class=xl35 style='border-top:none;border-left:none'>本期金额</td>
  <td class=xl35 style='border-top:none;border-left:none'>累计金额</td>
  <td class=xl35 style='border-top:none;border-left:none'>本期金额</td>
  <td class=xl35 style='border-top:none;border-left:none'>累计金额</td>
  <td class=xl35 style='border-top:none;border-left:none'>本期成本</td>
  <td class=xl35 style='border-top:none;border-left:none'>累计成本</td>
 </tr>
 <tr height=46 style='mso-height-source:userset;height:34.5pt'>
  <td height=46 class=xl35 style='height:34.5pt;border-top:none'>套管接箍</td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍产量%> </td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计产量%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍投入数量%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍投入金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计投入数量%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计投入金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍回收金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计回收金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍费用%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计费用%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍成本%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计成本%></td>
 </tr>
 <tr height=46 style='mso-height-source:userset;height:34.5pt'>
  <td height=46 class=xl35 style='height:34.5pt;border-top:none'>油管接箍</td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍产量%> </td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍累计产量%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍投入数量%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍投入金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍累计投入数量%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍累计投入金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍回收金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍累计回收金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍费用%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍累计费用%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍成本%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=油管接箍累计成本%></td>
 </tr>
 <tr height=47 style='mso-height-source:userset;height:35.25pt'>
  <td height=47 class=xl35 style='height:35.25pt;border-top:none'>合计</td>
  <td class=xl34 style='border-top:none;border-left:none'>　</td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计产量 + 油管接箍累计产量%></td>
  <td class=xl34 style='border-top:none;border-left:none'>　</td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍投入金额 + 油管接箍投入金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'>  </td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计投入金额+油管接箍累计投入金额 %></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍回收金额+油管接箍回收金额 %></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计回收金额+油管接箍累计回收金额%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍费用+油管接箍费用 %></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计费用+油管接箍累计费用 %></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍成本+油管接箍成本%></td>
  <td class=xl34 style='border-top:none;border-left:none'><%=套管接箍累计成本 + 油管接箍累计成本%></td>
 </tr>
 <tr height=29 style='mso-height-source:userset;height:21.75pt'>
  <td height=29 class=xl32 style='height:21.75pt;border-top:none'>　</td>
  <td class=xl32 style='border-top:none'>　</td>
  <td colspan=2 class=xl39>单位负责人：魏 君</td>
  <td class=xl32 style='border-top:none'>　</td>
  <td colspan=2 style='mso-ignore:colspan'></td>
  <td colspan=2 class=xl25 style='mso-ignore:colspan'></td>
  <td class=xl38 style='border-top:none'>制表：陈 霞</td>
  <td class=xl33 style='border-top:none'>　</td>
  <td class=xl32 style='border-top:none'>　</td>
  <td></td>
 </tr> 
</table> 
    </div>
    </form>
</body>
</html>
